/*
 * @Author: AI Generated
 * @Date: 2024-05-16
 * @Description: 留言模块控制器
 */
import {
    Body,
    Controller,
    Get,
    Param,
    Post,
    Put,
    Query,
} from '@nestjs/common';
import { RequiresPermissions } from 'src/common/decorators/requires-permissions.decorator';
import { PaginationPipe } from 'src/common/pipes/pagination.pipe';
import {
    AddSysFeedbackDto,
    GetSysFeedbackListDto,
    UpdateSysFeedbackRemarkDto,
} from './dto/req-sys-feedback.dto';
import { SysFeedbackService } from './sys-feedback.service';
import { BusinessTypeEnum, Log } from 'src/common/decorators/log.decorator';
import { RepeatSubmit } from 'src/common/decorators/repeat-submit.decorator';
import { CreateMessagePipe } from 'src/common/pipes/createmessage.pipe';
import { DataObj } from 'src/common/class/data-obj.class';
import { UpdateMessagePipe } from 'src/common/pipes/updatemessage.pipe';
import { Public } from 'src/common/decorators/public.decorator';

@Controller('system/feedback')
export class SysFeedbackController {
    constructor(private readonly sysFeedbackService: SysFeedbackService) { }

    /* 添加留言（小程序使用） */
    @Post()
    @Public()
    @RepeatSubmit()
    @Log({
        title: '留言管理',
        businessType: BusinessTypeEnum.insert,
        isSaveRequestData: false,
    })
    async add(@Body(CreateMessagePipe) addSysFeedbackDto: AddSysFeedbackDto) {
        return await this.sysFeedbackService.add(addSysFeedbackDto);
    }

    /* 分页查询留言列表 */
    @Get('list')
    @RequiresPermissions('system:feedback:query')
    async list(@Query(PaginationPipe) getSysFeedbackListDto: GetSysFeedbackListDto) {
        return await this.sysFeedbackService.list(getSysFeedbackListDto);
    }

    /* 通过id查询留言详情 */
    @Get(':feedbackId')
    @RequiresPermissions('system:feedback:query')
    async getById(@Param('feedbackId') feedbackId: number) {
        const feedback = await this.sysFeedbackService.getById(feedbackId);
        return DataObj.create(feedback);
    }

    /* 更新备注 */
    @Put('remark')
    @RepeatSubmit()
    @RequiresPermissions('system:feedback:edit')
    @Log({
        title: '留言管理',
        businessType: BusinessTypeEnum.update,
        isSaveRequestData: false,
    })
    async updateRemark(
        @Body(UpdateMessagePipe) updateSysFeedbackRemarkDto: UpdateSysFeedbackRemarkDto,
    ) {
        await this.sysFeedbackService.updateRemark(updateSysFeedbackRemarkDto);
    }
}